package com.question.business.auth.controller;

import com.question.business.auth.model.ao.LoginAO;
import com.question.business.auth.model.dto.CurrentUserDTO;
import com.question.business.auth.model.vo.LoginVO;
import com.question.business.auth.service.IAuthService;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 认证接口
 *
 * @author star
 * @since 2022/8/12
 */
@RestController
@AllArgsConstructor
@RequestMapping("/auth")
public class AuthController {

    private final IAuthService service;

    /**
     * 账号密码登陆认证
     *
     * @param ao 登陆数据
     * @return LoginVo
     */
    @PostMapping("/user/login")
    public LoginVO userLogin(@Validated @RequestBody LoginAO ao) {
        return service.userLogin(ao);
    }

    /**
     * 退出登陆认证
     */
    @PostMapping("/login/out")
    public void loginOut() {
        service.loginOut();
    }


    /**
     * 获取当前用户信息
     *
     * @return CurrentUserDTO
     */
    @GetMapping("/current/user")
    public CurrentUserDTO currentUser() {
        return service.currentUser();
    }

}
